<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>


    <title>banner新增</title>

    <link rel="shortcut icon" href="favicon.ico"/>
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet"/>
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet"/>
    <link href="css/animate.css" rel="stylesheet"/>
    <link href="css/style.css?v=4.1.0" rel="stylesheet"/>
    <link rel="shortcut icon" href="favicon.ico"/>
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet"/>
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="css/animate.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="css/plugins/simditor/simditor.css" />
    <link href="css/style.css?v=4.1.0" rel="stylesheet"/>

    <link rel="shortcut icon" href="favicon.ico"/>
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet"/>
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="css/animate.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="css/plugins/webuploader/webuploader.css"/>
    <link rel="stylesheet" type="text/css" href="css/demo/webuploader-demo.css"/>
    <link href="css/style.css?v=4.1.0" rel="stylesheet"/>
</head>

<body class="gray-bg">
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h1>banner添加 <small></small></h1>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                        <i class="fa fa-wrench"></i>
                    </a>
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content">
                <form class="form-horizontal" enctype="multipart/form-data">
                    <div class="form-group">
                        <!--<label class="col-sm-2 control-label">产品名称：</label>-->
                        <!--<select class="form-control m-b"  name="commodityid" style="width: 300px;">-->
                        <!--<option th:each="wl:${wl_commodity_getByCommodityNames}" th:text="${wl.commodityname}" th:value="${wl.id}"></option>-->
                        <!--</select>-->
                        <label class="col-sm-2 control-label">广告名称：</label>
                        <input required type="text" name="bannername" class="form-control" style="width: 300px;border-radius: 4%;"/><br/>


                        <label class="col-sm-2 control-label" id="labelchannel">显示渠道：</label>
                        <input  type="checkbox" name="channel" value="1">微信&#160;&#160;
                        <input  type="checkbox" name="channel" value="2">pc&#160;&#160;
                        <input  type="checkbox" name="channel" value="3">ios&#160;&#160;
                        <input  type="checkbox" name="channel" value="4">android
                        <br/>
                        <br/>
                        <label class="col-sm-2 control-label">活动地址：</label>
                        <select name="url"  class="col-sm-2">
                            <option th:each="sub:${wl_subject_list}" th:value="${sub.id}" th:text="${sub.subjectname}"></option>
                        </select>
                         <br/>
                        <br/>
                        <label id="labelstatus" class="col-sm-2 control-label">是否启用：</label>
                        <input required type="radio" name="status" checked="checked" value="1">启用
                        <input required type="radio" name="status" value="0">禁用
                        <br/>
                        <br/>
                        <label class="col-sm-2 control-label">显示顺序：</label>

                        <input required type="number" min="0" name="index" class="form-control" style="width: 300px;border-radius: 4%;"/><br/>

                        <br/>
                        <label class="col-sm-2 control-label">图片：</label>
                        <div class="wrapper wrapper-content animated fadeIn">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="ibox float-e-margins">
                                        <div class="ibox-content">
                                            <div class="page-container">
                                                <div id="uploader" class="wu-example">
                                                    <div class="queueList">
                                                        <div id="dndArea" class="placeholder">
                                                            <div id="filePicker"></div>
                                                            <p>或将照片拖到这里，单次最多可选300张</p>
                                                        </div>
                                                    </div>
                                                    <div class="statusBar" style="display:none;">
                                                        <div class="progress">
                                                            <span class="text">100%</span>
                                                            <span class="percentage"></span>
                                                        </div>
                                                        <div class="info"></div>
                                                        <div class="btns">
                                                            <div id="filePicker2"></div>
                                                            <div class="uploadBtn" onclick="uploadImage()">开始上传</div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <br/>
                        <br/>
                        <div id="upimage">
                        </div>


                    <button type="button" onclick="change()" class="btn btn-primary">保存信息</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>

<!-- simditor -->
<script type="text/javascript" src="js/plugins/simditor/module.js"></script>
<script type="text/javascript" src="js/plugins/simditor/uploader.js"></script>
<script type="text/javascript" src="js/plugins/simditor/hotkeys.js"></script>
<script type="text/javascript" src="js/plugins/simditor/simditor.js"></script>
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = 'js/plugins/webuploader';
</script>
<script src="js/plugins/webuploader/webuploader.min.js"></script>

<script src="js/demo/webuploader-demo.js"></script>

<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>
<script src="js/jquery.min.js"></script>
<script>

    function uploadImage() {
        var $lenth = $(".filelist li").length;
        for (var i=0;i<$lenth;i++) {
            var asd = $(".filelist li:eq("+i+")").children().children().attr("src");
            var asd1 = $(".filelist li:eq("+i+")").children('.title').text();
            asd = JSON.stringify(asd)
            $.ajax({
                type: 'POST',
                url: 'upImg',
                data: {
                    base64: asd,
                    imags:asd1
                },
                async: false,
                dataType: 'json',
                success: function (data) {
                    //alert(data.valueOf())
                    if (data.valueOf()) {
                        alert('上传成功');
                        $("#upimage").append("<input type='hidden' id='1w' name='image' value='"+asd1+"'/>");
                    } else {
                        alert('上传失败');
                    }
                },
                error: function (err) {
                    alert('网络故障');
                }
            });
        }
    }

    function change() {
        //获取广告名称
        var bannername = $("[name=bannername]").val();
        //获取渠道
        var channel = document.getElementsByName("channel");
        var channels = "";
        for (var i =0;i<channel.length;i++){
            if(channel[i].checked){
                if(channels=="")
                    channels = channel[i].value;
                else
                channels = channels+channel[i].value;
            }
        }
        alert(channels);
        //获取活动地址
        var url = $("[name=url]").val();
        //获取启用状态
        var status = $("[name=status]:checked").val();
        //显示顺序
        var index = $("[name=index]").val();
        //图片
        var image = $("[name=image]").val();
        $.ajax(
            {
                url:'wl_banner_insert',
                type:'post',
                data:{
                    bannername:bannername,
                    channel:channels,
                    url:url,
                    status:status,
                    index:index,
                    image:image
                },
                dataType:'json',
                success:function (data) {
                    if(data>0){
                        alert("新增成功");
                        window.location.href="wl_banner_getall";
                        return;
                    }else
                        alert("新增失败");
                }
            }
        )
    }
</script>

<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<!--统计代码，可删除-->

</body>

</html>
